package com.csu.device.service.impl;

import com.csu.device.dao.BehaviorDao;
import com.csu.device.dao.BigScreenDao;
import com.csu.device.service.BigScreenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class BigScreenServiceImpl implements BigScreenService {

    @Autowired
    private BigScreenDao bigScreenDao;

    @Autowired
    private  BehaviorDao behaviorDao;

    @Override
    public List<Map<String, Object>> findTomatic(Map<String, Object> map) {
        return bigScreenDao.findTomatic(map);
    }

    @Override
    public List<Map<String, Object>> findDevice(Map<String, Object> map) {
        return bigScreenDao.findDevice(map);
    }

    @Override
    public List<Map<String, Object>> findBehavior(Map<String, Object> map) {
        return  bigScreenDao.findBehavior(map);
    }

    @Override
    public Map<String, List<Map<String, Object>>> findAllBehaviorGroupByScene(Map<String, Object> map) {


        Map<String, List<Map<String, Object>>> map2=new HashMap<>();
        this.fenZu(behaviorDao.findAllBehaviorGroupByScene(map),map2);
        return map2;
    }

    @Override
    public List<Map<String, Object>> findAllRoom(Map<String, Object> map) {
        return bigScreenDao.findAllRoom(map);
    }


    public  void fenZu(List<Map<String, Object>> list, Map<String, List<Map<String, Object>>> map) {//map是用来接收分好的组的
        if (null == list || null == map) {
            return;
        }
        String key;
        List<Map<String, Object>> listTmp;
        for (Map val : list) {
            key = val.get("date").toString();
            listTmp = map.get(key);
            if (null == listTmp) {
                listTmp = new ArrayList <Map<String, Object>>();
                map.put(key, listTmp);
            }
            listTmp.add(val);
        }
    }
}
